package com.zzyl.controller;


import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.NursingProjectDto;
import com.zzyl.service.NursingProjectService;
import com.zzyl.vo.NursingProjectVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.ibatis.annotations.Delete;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.yaml.snakeyaml.events.Event;

import java.util.List;

@RestController
@RequestMapping("/nursing_project")
@Api(tags = "护理项目相关接口")
public class NursingProjectController extends BaseController {

    @Autowired
    private NursingProjectService nursingProjectService;


    @GetMapping("/all")
    @ApiOperation("获取所有护理项目")
    public ResponseResult<NursingProjectVo> getAllProject() {
        List<NursingProjectVo> list = nursingProjectService.getAllProject();
        return ResponseResult.success(list);
    }

    @GetMapping
    @ApiOperation("分页条件查询护理项目")
    public ResponseResult selectByPage(@ApiParam(value = "护理项目名称") String name, Integer status, Integer pageNum, Integer pageSize) {
        PageResponse pageResponse = nursingProjectService.selectByPage(name, status, pageNum, pageSize);
        return success(pageResponse);
    }

    @PostMapping
    @ApiOperation("新增护理项目")
    public ResponseResult add(
            @ApiParam(value = "护理项目数据传输对象", required = true)
            @RequestBody NursingProjectDto nursingProjectDTO) {
        nursingProjectService.add(nursingProjectDTO);
        return ResponseResult.success();
    }

    @GetMapping("/{id}")
    public ResponseResult<NursingProjectVo> getById(
            @PathVariable("id") Long id) {
        NursingProjectVo nursingProjectVO = nursingProjectService.getById(id);
        return ResponseResult.success(nursingProjectVO);
    }

    @PutMapping
    @ApiOperation("修改护理项目")
    public ResponseResult update(@RequestBody NursingProjectDto nursingProjectDTO) {
        nursingProjectService.update(nursingProjectDTO);
        return ResponseResult.success();
    }

    @DeleteMapping("/{id}")
    @ApiOperation("根据id删除护理项目")
    public ResponseResult deleteById(@ApiParam("项目id") @PathVariable Long id) {
        ResponseResult responseResult = nursingProjectService.deleteById(id);
        return responseResult;
    }
    @PutMapping("/{id}/status/{status}")
    @ApiOperation("根据id修改状态")
    public  ResponseResult updateStatusById(@ApiParam("项目id") @PathVariable Long id,
                                            @ApiParam("状态") @PathVariable Integer status)
    {
        nursingProjectService.updateStatusById(id,status);
        return ResponseResult.success();
    }
}
